package com.qf.mapper;

import com.qf.model.*;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

@Mapper
public interface DeviceGatherMapper {

    @Select("select * from device_gather")
    List<DeviceGather> getAll();

    @Results(id = "DeviceGatherMap",value = {
            @Result(column = "id",property = "id"),
            @Result(column = "deviceId",property = "deviceId"),
            @Result(column = "deviceSn",property = "deviceSn"),
            @Result(column = "deviceName",property = "deviceName"),
            @Result(column = "deviceType",property = "deviceType"),
            @Result(column = "basicData",property = "basicData"),
            @Result(column = "gatherTime",property = "gatherTime"),
            @Result(column = "createTime",property = "createTime"),
            @Result(column = "updateTime",property = "updateTime"),
            @Result(column = "deviceId",property ="device",javaType = Device.class,one=
            @One(select = "com.qf.mapper.DeviceMapper.findDevice" ,fetchType = FetchType.EAGER)
            )
//            ,
//            @Result(column = "deviceType",property ="deviceType",javaType = DeviceType.class,one=
//            @One(select = "com.qf.mapper.DeviceTypeMapper.findDeviceType" ,fetchType = FetchType.EAGER)
//            )
    })

    @Select("select * from device_gather limit #{currentPage},#{pageSize}")
    List<DeviceGather> findPage(@Param("currentPage") Integer currentPage,@Param("pageSize") Integer pageSize);

    @Select("select count(*) from device_gather")
    long count();

    @Insert("insert into device_gather (deviceId,deviceSn,deviceName,deviceType,basicData,gatherTime,createTime,updateTime) values (#{deviceId},#{deviceSn},#{deviceName},#{deviceType},#{basicData},#{gatherTime},#{createTime},#{updateTime})")
    int insertDeviceGather(DeviceGather deviceGather);

    @Select("select * from device_gather where id =#{id}")
    DeviceGather findDeviceGather(int id);

    @Update("update device_gather set deviceId=#{deviceId},deviceSn=#{deviceSn},deviceName=#{deviceName},deviceType=#{deviceType},basicData=#{basicData},gatherTime=#{gatherTime},createTime=#{createTime},updateTime=#{updateTime} where id=#{id}")
    int update(DeviceGather deviceGather);

    @Delete("delete from device_gather where id =#{id}")
    int delDeviceGather(Integer id);
}
